package com.pcjavanet.generate;

import java.io.BufferedReader;
import java.io.FileReader;

public class AppendLsFile {
	public void appendLsAction(String smallBeanName,String sourceFilePath){
		try {
			StringBuffer appendBuf = new StringBuffer();
			FileReader read = new FileReader(sourceFilePath);
			BufferedReader br = new BufferedReader(read);
			String row;
			String appendLine = "<li><a href=\"<%=request.getContextPath() %>/"+smallBeanName + "/index.action\">"+smallBeanName+"</a>\r\n";
			boolean findFlag = false ; 
			while ((row = br.readLine()) != null) {
				if ( row.indexOf(  smallBeanName ) != -1 ){
					findFlag = true ; 
				}
				if ( row.indexOf( "<div id=\"beforeAppendFlag\"></div>" ) != -1 ) {
					if ( findFlag == false )
						appendBuf.append( appendLine );
				}
				appendBuf.append(row).append("\r\n");
			}
			FileUtil.contentToSave(sourceFilePath, appendBuf.toString() );
		}catch (Exception e){
			e.printStackTrace();
		}
	}
}
